package com.tanhua.server.controller;

import com.tanhua.model.dto.RecommentUserDto;
import com.tanhua.model.vo.NearUserVO;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.TanhuaService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.aggregation.ArrayOperators;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Xiao
 * @date 2021/10/24
 */
@RestController
@RequestMapping("/tanhua")
public class TanhuaController {
    @Autowired
    private TanhuaService tanhuaService;

    /**
     * 交友-今日佳人
     *
     * @return
     */
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        TodayBest todayBestVO = tanhuaService.todayBest();
        return ResponseEntity.ok(todayBestVO);
    }

    /**
     * 交友-推荐朋友
     *
     * @param recommentUserDto
     * @return
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommentUserDto recommentUserDto) {
        PageResult pageResult = tanhuaService.recommendation(recommentUserDto);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 交友-佳人信息
     *
     * @param userId
     * @return
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId) {
        TodayBest todayBest = tanhuaService.personalInfo(userId);
        return ResponseEntity.ok(todayBest);
    }

    /**
     * 交友 -- 佳人信息 -- 聊一下 -- 查询陌生人问题
     *
     * @param userId
     * @return
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity getStrangerQuestions(Long userId) {
        String strangerQuestion = tanhuaService.getStrangerQuestion(userId);
        return ResponseEntity.ok(strangerQuestion);
    }

    /**
     * 交友 -- 佳人信息 -- 聊一下 -- 回复陌生人问题
     *
     * @param map
     * @return
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyStrangerQuestions(@RequestBody Map map) {
        Long userId = Long.valueOf(map.get("userId").toString());
        String reply = map.get("reply").toString();
        tanhuaService.replyStrangerQuestion(userId, reply);
        return ResponseEntity.ok("发送成功！");
    }

    /**
     * 探花-左滑右滑卡片
     * @return
     */
    @GetMapping("/cards")
    public ResponseEntity getCards() {
        List<TodayBest> todayBests = tanhuaService.getCards();
        return ResponseEntity.ok(todayBests);
    }

    /**
     * 探花-喜欢(右滑)/不喜欢(左滑)
     * @param likeUserId
     * @param loveParam love/unlove
     * @return
     */
    @GetMapping("/{id}/{loveParam}")
    public ResponseEntity love(@PathVariable("id") Integer likeUserId,
                               @PathVariable("loveParam") String loveParam) {
        Boolean direction = StringUtils.equals("love", loveParam);
        tanhuaService.love(Long.valueOf(likeUserId), direction);
        return ResponseEntity.ok("滑动成功！");
    }

    /**
     * 探花-搜索附近
     * @param gender
     * @param distance
     * @return
     */
    @GetMapping("/search")
    public ResponseEntity search(String gender,
                                 @RequestParam(defaultValue = "2000") String distance) {
        List<NearUserVO> nearUserVOs = tanhuaService.search(gender, Double.valueOf(distance));
        return ResponseEntity.ok(nearUserVOs);
    }
}
